package org.magento.pages;

import java.util.NoSuchElementException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

/*This is parent class for all pages 
 * It contains main functions 
 */
public abstract class Page {
	
	protected WebDriver driver;
	
	public Page (WebDriver driver) {
		this.driver = driver;
	}
	
	//Type method
	protected void type (WebElement webElement, String text) {
		webElement.clear();
		webElement.sendKeys(text);
	}
	
	//Select from drop-dawn menu method 
	protected void select(WebElement webElement, String text) {
		webElement.sendKeys(text);
	}
	
	//open page method 
	public abstract void open();
	
	//Wait for 1 sec  mehod 
	public void waitForOneSeconds() throws Exception {
		Thread.sleep(1000);
	}
	
	//Wait for 3 sec  mehod 
		public void waitForThreeSeconds() throws Exception {
			Thread.sleep(3000);
		}
		
	//Wait for 5 sec method 
	public void waitForFiveSeconds() throws Exception {
		Thread.sleep(5000);
	}
	
	
	//Assertion is element present method
	public boolean isElementPresent (WebElement element) {
		try {
			element.isDisplayed();
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}
